home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / autojpeg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-01-15  |  18.4 KB  |  608 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 2001                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10.  
  11. // AutoJPEG.cpp : implementation file
  12. //
  13.  
  14. #include "stdafx.h"
  15. #include "JPEG.h"
  16. #include "AutoJPEG.h" // This class
  17.  
  18. // How to create a JPEG?
  19. #ifdef USE_LEADTOOOLS
  20. // Source code license required
  21. #else
  22. // Exported function from JPEGLIB.DLL 
  23. __declspec(dllimport) extern "C" int DIBToJPEG(HGLOBAL hDib, LPCSTR outfilename);
  24. #endif
  25.  
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31.  
  32. // Standard variants
  33. COleVariant t(-1L, VT_BOOL);
  34. COleVariant f(0L, VT_BOOL);
  35. COleVariant missing((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
  36.  
  37. // IID's From Imsigx.i_c.
  38. const IID IID_Graphics = 
  39.     {0x6A48110A,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  40. const IID IID_Filter = 
  41.     {0x6A48111B,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CAutoJPEG
  45.  
  46. // We get all these functions from the Visual C++ ClassWizard...
  47.  
  48. IMPLEMENT_DYNCREATE(CAutoJPEG, CCmdTarget)
  49.  
  50. CAutoJPEG::CAutoJPEG()
  51. {
  52.     EnableAutomation();
  53.     
  54.     // To keep the application running as long as an OLE automation 
  55.     //    object is active, the constructor calls AfxOleLockApp.
  56.     
  57.     AfxOleLockApp();
  58. }
  59.  
  60. CAutoJPEG::~CAutoJPEG()
  61. {
  62.     // To terminate the application when all objects created with
  63.     //     with OLE automation, the destructor calls AfxOleUnlockApp.
  64.     
  65.     AfxOleUnlockApp();
  66. }
  67.  
  68.  
  69. void CAutoJPEG::OnFinalRelease()
  70. {
  71.     // When the last reference for an automation object is released
  72.     // OnFinalRelease is called.  The base class will automatically
  73.     // deletes the object.  Add additional cleanup required for your
  74.     // object before calling the base class.
  75.  
  76.     CCmdTarget::OnFinalRelease();
  77. }
  78.  
  79.  
  80. BEGIN_MESSAGE_MAP(CAutoJPEG, CCmdTarget)
  81.     //{{AFX_MSG_MAP(CAutoJPEG)
  82.         // NOTE - the ClassWizard will add and remove mapping macros here.
  83.     //}}AFX_MSG_MAP
  84. END_MESSAGE_MAP()
  85.  
  86. BEGIN_DISPATCH_MAP(CAutoJPEG, CCmdTarget)
  87.     //{{AFX_DISPATCH_MAP(CAutoJPEG)
  88.     DISP_PROPERTY_EX(CAutoJPEG, "ClassID", GetClassID, SetNotSupported, VT_BSTR)
  89.     DISP_PROPERTY_EX(CAutoJPEG, "Description", GetDescription, SetNotSupported, VT_BSTR)
  90.     DISP_PROPERTY_EX(CAutoJPEG, "Info", GetInfo, SetNotSupported, VT_BSTR)
  91.     DISP_PROPERTY_EX(CAutoJPEG, "LastError", GetLastError, SetNotSupported, VT_BSTR)
  92.     DISP_FUNCTION(CAutoJPEG, "CheckFlat", CheckFlat, VT_I4, VTS_DISPATCH VTS_BSTR VTS_I4 VTS_PVARIANT)
  93.     DISP_FUNCTION(CAutoJPEG, "PreviewFlat", PreviewFlat, VT_I4, VTS_DISPATCH VTS_BSTR VTS_I4 VTS_I4 VTS_PBSTR VTS_PVARIANT)
  94. // decoment second string to get this filter in OpenFile filters list
  95. //    DISP_FUNCTION(CAutoJPEG, "ReadFlat", ReadFlat, VT_I4, VTS_BSTR VTS_I4 VTS_DISPATCH VTS_PVARIANT)
  96.     DISP_FUNCTION(CAutoJPEG, "WriteFlat", WriteFlat, VT_I4, VTS_BSTR VTS_I4 VTS_DISPATCH VTS_PVARIANT)
  97.     DISP_FUNCTION(CAutoJPEG, "ReadSetup", ReadSetup, VT_BOOL, VTS_DISPATCH)
  98.     DISP_FUNCTION(CAutoJPEG, "WriteSetup", WriteSetup, VT_BOOL, VTS_DISPATCH)
  99.     DISP_FUNCTION(CAutoJPEG, "Initialize", Initialize, VT_BOOL, VTS_DISPATCH)
  100.     //}}AFX_DISPATCH_MAP
  101. END_DISPATCH_MAP()
  102.  
  103. // Note: we add support for IID_ITurboCADFilter to support typesafe binding
  104. //  from VBA.  This IID must match the GUID that is attached to the 
  105. //  dispinterface in the .ODL file.  Do not change this GUID if make your own custom filter!
  106.  
  107. // {6A481302-E531-11CF-A115-00A024158DAF}
  108. static const IID IID_ITurboCADFilter =
  109. {0x6A481302,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  110.  
  111. BEGIN_INTERFACE_MAP(CAutoJPEG, CCmdTarget)
  112.     INTERFACE_PART(CAutoJPEG, IID_ITurboCADFilter, Dispatch)
  113. END_INTERFACE_MAP()
  114.  
  115. // Note: if you make a custom filter by copying this file, make sure to replace the following
  116. //  GUID with a new GUID that matches the uuid statement in the coclass declaration in the 
  117. //  .ODL file.  This is the GUID that OLE will use to register and create the automation object.
  118.  
  119. // {28696026-B7E6-11D0-9B3B-444553540000}
  120. IMPLEMENT_OLECREATE(CAutoJPEG, "JPEG.AutoJPEG", 0x28696026, 0xb7e6, 0x11d0, 0x9b, 0x3b, 0x44, 0x45, 0x53, 0x54, 0x0, 0x0)
  121.  
  122. /////////////////////////////////////////////////////////////////////////////
  123. // CAutoJPEG message handlers
  124.  
  125. // GetClassID:  return the filter's class id, as a string.
  126.  
  127. BSTR CAutoJPEG::GetClassID() 
  128. {
  129.     // Convert our GUID (see IMPLEMENT_OLECREATE macro) to a string
  130.     LPOLESTR olestr;
  131.     HRESULT hRes = ::StringFromCLSID(guid, &olestr);
  132.     if (FAILED(hRes))
  133.         return NULL;
  134.  
  135.     BSTR bstr = ::SysAllocString(olestr);
  136.     CoTaskMemFree(olestr);
  137.     return bstr;
  138. }
  139.  
  140. // GetDescription:  return the filter's description.
  141.  
  142. BSTR CAutoJPEG::GetDescription() 
  143. {
  144.     // Get the description from the resource
  145.     CString strResult;
  146.     strResult.LoadString(IDS_AUTOJPEG_DESC);
  147.  
  148.     return strResult.AllocSysString();
  149. }
  150.  
  151. // GetInfo:  return the filter's info string
  152. // Our info string is "JPEG.AutoJPEG,JPEG (JFIF) File,0,10,JPG,JPG", stored in the DLL's
  153. // resource.
  154.  
  155. // The info string contains the following fields, delimited by commas:
  156. // Field Name                                Value
  157. // 1.    Filter ID                           "JPEG.AutoJPEG"  
  158. //        Used as the internal name (must be unique).
  159. //        Should be the same as the ProgID registered for the server.
  160. //        TurboCAD reserves names beginning with an asterisk.
  161. // 2.    File type string for common dialog  "JPEG (JFIF) File";  
  162. //        This string appears in Windows dialog file type combo box.
  163. // 3.    Document type handled by filter     0
  164. //        This should always be zero for automation filters.
  165. // 4.    Priority                            10
  166. //        Arbitrary integer value used to determine search order for multiple filters which
  167. //        support the same document type and file extension.
  168. // 5.    Exported function name prefix       "JPG"
  169. //        Not used by automation filters, but a non-blank string must be supplied.
  170. // 6-n.  File extensions                     "JPG"
  171. //        Used in common dialog and for matching.
  172.  
  173. BSTR CAutoJPEG::GetInfo() 
  174. {
  175.     // Get the description from the resource
  176.     CString strResult;
  177.     strResult.LoadString(IDS_AUTOJPEG_INFO);
  178.  
  179.     return strResult.AllocSysString();
  180. }
  181.  
  182.  
  183. // GetLastError:  return descriptive information about the last error that occurred during an
  184. // open or save operation.  A smarter filter would save state somewhere and return better
  185. // diagnostics.
  186.  
  187. BSTR CAutoJPEG::GetLastError() 
  188. {
  189.     CString strResult;
  190.     strResult.LoadString(IDS_AUTOJPEG_ERROR_UNKNOWN);
  191.  
  192.     return strResult.AllocSysString();
  193. }
  194.  
  195. // CheckFlat:  file readers get called with this method to see if they can read the file.
  196. // If we were a file reader, we would look for a JPEG header.
  197.  
  198. long CAutoJPEG::CheckFlat(LPDISPATCH ThisFilter, LPCTSTR FileName, long ContextFlags, VARIANT FAR* QueryString) 
  199. {
  200.     // We are not implementing a reader
  201.     AfxThrowOleException(E_NOTIMPL);
  202.     return 0;
  203. }
  204.  
  205. // PreviewFlat:  file readers get called with this method to get a description string and a
  206. // (bitmap or metafile) thumbnail from the file.  If we were a file reader, we would create a
  207. // bitmap or StdPicture object from the JPEG file.
  208.  
  209. long CAutoJPEG::PreviewFlat(LPDISPATCH ThisFilter, LPCTSTR FileName, long ThumbWidth, long ThumbHeight, BSTR FAR* Description, VARIANT FAR* Thumbnail) 
  210. {
  211.     // We are not implementing a reader
  212.     AfxThrowOleException(E_NOTIMPL);
  213.     return 0;
  214. }
  215.  
  216. // ReadFlat:  file readers get called with this method to read graphics from the file and
  217. // add to the Graphics collection.  The Drawing object that we're reading into can be 
  218. // obtained by calling Graphics->get_Drawing.
  219.  
  220. long CAutoJPEG::ReadFlat(LPCTSTR FileName, long ContextFlags, LPDISPATCH Graphics, VARIANT FAR* QueryString) 
  221. {
  222.     // We are not implementing a reader
  223.     AfxThrowOleException(E_NOTIMPL);
  224.     return 0;
  225. }
  226.  
  227. // WriteFlat:  file writers get called with this method to write graphics to the file.
  228. // The Drawing object that we're writing from from is obtained by calling Graphics->get_Drawing.
  229.  
  230. long CAutoJPEG::WriteFlat(LPCTSTR FileName, long ContextFlags, LPDISPATCH Grfs, VARIANT FAR* QueryString) 
  231. {
  232.     long nError = -101;
  233.  
  234.     try
  235.     {
  236.         Graphics* pGraphics = NULL;
  237.         if (FAILED(Grfs->QueryInterface(IID_Graphics, (void**)&pGraphics)))
  238.             return -101;
  239.  
  240.     #ifdef USE_LEADTOOLS
  241.         // Source code license required!
  242.  
  243.         // If we were licensed, we could accomplish the task as follows:
  244.         //   1. Use LEADTOOLS to get a (bitmap) DC to draw onto.
  245.         //   2. Set up a View on our drawing with this DC.
  246.         //   3. Refresh the View (painting onto its DC).
  247.         //   4. Let LEADTOOLS or another utility to save the bitmap on the DC to a JPEG file.
  248.         //   5. Destroy the DC.
  249.  
  250.     #else
  251.         // Since we're using our custom JPEG library (which expects a DIB in memory), we will:
  252.         //   1. Set up a View on our drawing (no DC necessary).
  253.         //   2. Open a bitmap DC on the View.
  254.         //   3. Refresh the View (painting onto its DC).
  255.         //   4. Close the bitamp DC and retrieve the DIB.
  256.         //   5. Pass the DIB to our special function DIBToJPEG.
  257.         //   6. Dispose of the memory in the DIB.
  258.  
  259.         // Copyright notice:  DIBToJPEG is an exported function, part of a DLL created using the 
  260.         //  Independent JPEG Group's JPEG encoding/decoding library, modified in part by IMSI.
  261.         //  Please read the file "README" that is in this directory for more information on
  262.         //  JPEG, the IJG and the JPEG library.
  263.  
  264. //        long nError = -101;
  265.  
  266.         HGLOBAL hDib = NULL;
  267.         IDrawing* pIDrawing = NULL;
  268.         if (SUCCEEDED(pGraphics->get_Drawing(&pIDrawing)))
  269.         {
  270.             Views* pViews = NULL;
  271.             if (SUCCEEDED(pIDrawing->get_Views(&pViews)))
  272.             {
  273.                 View* pView = NULL;
  274.                 if (SUCCEEDED(pViews->Add(&missing, &missing, &pView)))
  275.                 {
  276.                     // To set the image width and height, we use settings stored in
  277.                     // TurboCAD's INI file.  These settings are transfered to our 
  278.                     // WriteSetup dialog for use by us.  See comments on the WriteSetup
  279.                     // function below, and the code in WSetup.cpp for more information.
  280.                     IApplication* pIApp;
  281.                     if (SUCCEEDED(pGraphics->get_Application(&pIApp)))
  282.                     {
  283.                         CString strProfileName;
  284.                         if (GetProfileName(pIApp, strProfileName))
  285.                             m_dlg.FromProfile(strProfileName);
  286.                         pIApp->Release();
  287.                     }
  288.                     
  289.                     // Set up size for bitmap DC
  290.                     HRESULT hRes;
  291.                     hRes = pView->put_Update(FALSE);
  292.                     hRes = pView->put_MappingMode(MM_TEXT);
  293.                     hRes = pView->put_ScreenLeft(0.0);
  294.                     hRes = pView->put_ScreenTop(0.0);
  295.                     hRes = pView->put_ScreenWidth((double)m_dlg.m_nWidth);
  296.                     hRes = pView->put_ScreenHeight((double)m_dlg.m_nHeight);
  297.                     hRes = pView->ZoomToExtents(); 
  298.                     hRes = pView->put_Update(TRUE);
  299.  
  300.                     // Draw our extents on the View as a bitmap
  301.                     long lBitmapDC = 0;
  302.                     hRes = pView->OpenBitmapDC(&lBitmapDC);
  303.                     if (SUCCEEDED(hRes))
  304.                     {
  305.                         hRes = pView->Refresh();
  306.                         hRes = pView->CloseBitmapDC((long*)&hDib);
  307.                     }
  308.  
  309.                     // Done with view
  310.                     pView->Delete();
  311.                     pView->Release();
  312.                 }
  313.                 pViews->Release();
  314.             }
  315.             pIDrawing->Release();
  316.         }
  317.  
  318.         if (hDib != NULL)
  319.         {
  320.             // Use function in JPEGLIB.DLL to save as a JPEG(JFIF) file
  321.             // Should work with 8, 16, and 24-bit DIBs
  322.             nError = DIBToJPEG(hDib, FileName);
  323.             ::GlobalFree(hDib);
  324.         }
  325.     #endif
  326.  
  327.         pGraphics->Release();
  328. }
  329. catch(...)
  330. {
  331.     TRACE("Exception in CAutoJPEG::WriteFlat");
  332. }
  333.     if (nError == -555)
  334.     {
  335.         AfxMessageBox("This sample doesn't work for display setting True Color (32 Bit)!"); 
  336.         nError = 0;
  337.     }
  338.     return nError;
  339. }
  340.  
  341. // ReadSetup:  called to allow user interface for file read settings.
  342.  
  343. BOOL CAutoJPEG::ReadSetup(LPDISPATCH ThisFilter) 
  344. {
  345.     // We are not implementing a reader.
  346.     AfxThrowOleException(E_NOTIMPL);
  347.  
  348.     return TRUE;
  349. }
  350.  
  351. // WriteSetup:  called to allow user interface for file write settings.
  352. // Our example allows users to specify the width and height of the JPEG image.
  353. // We could (with a little more work) control the bit depth, compression, etc.
  354.  
  355. BOOL CAutoJPEG::WriteSetup(LPDISPATCH ThisFilter) 
  356. {
  357.     // We store these settings in TurboCAD's INI file.
  358.     // First, get the file name.
  359.     CString strProfileName;
  360.     if (ThisFilter != NULL)
  361.     {
  362.         Filter* pFilter;
  363.         HRESULT hRes = ThisFilter->QueryInterface(IID_Filter, (void**)&pFilter);
  364.         if (SUCCEEDED(hRes))
  365.         {
  366.             IApplication* pIApp;
  367.             hRes = pFilter->get_Application(&pIApp);
  368.             if (SUCCEEDED(hRes))
  369.             {
  370.                 GetProfileName(pIApp, strProfileName);
  371.                 pIApp->Release();
  372.             }
  373.             pFilter->Release();
  374.         }
  375.     }
  376.  
  377.     // Initialize the setup dialog from the INI file, and run the dialog.
  378.     if (!strProfileName.IsEmpty())
  379.         m_dlg.FromProfile(strProfileName);
  380.     if (m_dlg.DoModal() == IDOK)
  381.     {
  382.         // Update the INI file if the user clicked OK
  383.         if (!strProfileName.IsEmpty())
  384.             m_dlg.ToProfile(strProfileName);
  385.     }
  386.     return TRUE;
  387. }
  388.  
  389. // Function called when Filter object has been added to application at startup.
  390. // We could install an event listener here, allocate memory, or whatever.
  391.  
  392. BOOL CAutoJPEG::Initialize(LPDISPATCH ThisFilter) 
  393. {
  394.     // We just return TRUE for success.  Returning FALSE would remove our Filter.
  395.     return TRUE;
  396. }
  397.  
  398. // Helper function for filter settings (accessed in WriteSetup).
  399. // We will store our settings in TurboCAD's INI file.
  400. // Another option is to store the settings in the Windows registry.
  401.  
  402. BOOL CAutoJPEG::GetProfileName(IApplication* pIApp, CString& strProfileName)
  403. {
  404.     BSTR bstrProfile;
  405.     HRESULT hRes = pIApp->get_ProfileName(0, &bstrProfile);
  406.     if (SUCCEEDED(hRes))
  407.     {
  408.         strProfileName = bstrProfile;
  409.         ::SysFreeString(bstrProfile);
  410.         return TRUE;
  411.     }
  412.     return FALSE;
  413. }
  414.  
  415. // DUAL_SUPPORT_START
  416. // The rest of this file is boilerplate dual interface stuff.  We use macros from MfcDual.h
  417. // and just wrap all of our implementation functions in TRY/CATCH blocks.
  418.  
  419. // delegate standard IDispatch methods to MFC IDispatch implementation
  420. DELEGATE_DUAL_INTERFACE(CAutoJPEG, DualJPEG)
  421.  
  422. // Our method and property functions can generally just
  423. // delegate back to the methods we generated using 
  424. // ClassWizard. However, if we set up properties to 
  425. // access variables directly, we will need to write the
  426. //  code to get/put the value into the variable.
  427. STDMETHODIMP CAutoJPEG::XDualJPEG::get_ClassID(BSTR FAR* retval)
  428. {
  429.     if (retval == NULL)
  430.         return E_POINTER;
  431.  
  432.     METHOD_PROLOGUE(CAutoJPEG, DualJPEG)
  433.  
  434.     TRY_DUAL(IID_ITurboCADFilter)
  435.     {
  436.         *retval = pThis->GetClassID();
  437.         return S_OK;
  438.     }
  439.     CATCH_ALL_DUAL
  440. }
  441.  
  442. STDMETHODIMP CAutoJPEG::XDualJPEG::get_Description(BSTR FAR* retval)
  443. {
  444.     if (retval == NULL)
  445.         return E_POINTER;
  446.  
  447.     METHOD_PROLOGUE(CAutoJPEG, DualJPEG)
  448.  
  449.     TRY_DUAL(IID_ITurboCADFilter)
  450.     {
  451.         *retval = pThis->GetDescription();
  452.         return S_OK;
  453.     }
  454.     CATCH_ALL_DUAL
  455. }
  456.  
  457. STDMETHODIMP CAutoJPEG::XDualJPEG::get_Info(BSTR FAR* retval)
  458. {
  459.     if (retval == NULL)
  460.         return E_POINTER;
  461.  
  462.     METHOD_PROLOGUE(CAutoJPEG, DualJPEG)
  463.  
  464.     TRY_DUAL(IID_ITurboCADFilter)
  465.     {
  466.         *retval = pThis->GetInfo();
  467.         return S_OK;
  468.     }
  469.     CATCH_ALL_DUAL
  470. }
  471.  
  472. STDMETHODIMP CAutoJPEG::XDualJPEG::get_LastError(BSTR* retval)
  473. {
  474.     if (retval == NULL)
  475.         return E_POINTER;
  476.  
  477.     METHOD_PROLOGUE(CAutoJPEG, DualJPEG)
  478.  
  479.     TRY_DUAL(IID_ITurboCADFilter)
  480.     {
  481.         *retval = pThis->GetLastError();
  482.         return S_OK;
  483.     }
  484.     CATCH_ALL_DUAL
  485. }
  486.  
  487. STDMETHODIMP CAutoJPEG::XDualJPEG::CheckFlat(IDispatch* ThisFilter, BSTR FileName, long ContextFlags, VARIANT FAR* QueryString, long FAR* retval)
  488. {
  489.     if (retval == NULL)
  490.         return E_POINTER;
  491.  
  492.     METHOD_PROLOGUE(CAutoJPEG, DualJPEG)
  493.  
  494.     TRY_DUAL(IID_ITurboCADFilter)
  495.     {
  496.         CString strFileName(FileName);
  497.         *retval = pThis->CheckFlat(ThisFilter, strFileName, ContextFlags, QueryString);
  498.         return S_OK;
  499.     }
  500.     CATCH_ALL_DUAL
  501. }
  502.  
  503. STDMETHODIMP CAutoJPEG::XDualJPEG::PreviewFlat(IDispatch* ThisFilter, BSTR FileName, long ThumbWidth, long ThumbHeight, BSTR FAR* Description, VARIANT FAR* Thumbnail, long FAR* retval)
  504. {
  505.     if (retval == NULL)
  506.         return E_POINTER;
  507.  
  508.     METHOD_PROLOGUE(CAutoJPEG, DualJPEG)
  509.  
  510.     TRY_DUAL(IID_ITurboCADFilter)
  511.     {
  512.         CString strFileName(FileName);
  513.         *retval = pThis->PreviewFlat(ThisFilter, strFileName, ThumbWidth, ThumbHeight, Description, Thumbnail);
  514.         return S_OK;
  515.     }
  516.     CATCH_ALL_DUAL
  517. }
  518.  
  519.  
  520. STDMETHODIMP CAutoJPEG::XDualJPEG::ReadFlat(BSTR FileName, long ContextFlags, IDispatch * Graphics, VARIANT FAR* QueryString, long FAR* retval)
  521. {
  522.     if (retval == NULL)
  523.         return E_POINTER;
  524.  
  525.     METHOD_PROLOGUE(CAutoJPEG, DualJPEG)
  526.  
  527.     TRY_DUAL(IID_ITurboCADFilter)
  528.     {
  529.         CString strFileName(FileName);
  530.         *retval = pThis->ReadFlat(strFileName, ContextFlags, Graphics, QueryString);
  531.         return S_OK;
  532.     }
  533.     CATCH_ALL_DUAL
  534. }
  535.  
  536.  
  537. STDMETHODIMP CAutoJPEG::XDualJPEG::WriteFlat(BSTR FileName, long ContextFlags, IDispatch * Graphics, VARIANT FAR* QueryString, long FAR* retval)
  538. {
  539.     if (retval == NULL)
  540.         return E_POINTER;
  541.  
  542.     METHOD_PROLOGUE(CAutoJPEG, DualJPEG)
  543.  
  544.     TRY_DUAL(IID_ITurboCADFilter)
  545.     {
  546.         CString strFileName(FileName);
  547.         *retval = pThis->WriteFlat(strFileName, ContextFlags, Graphics, QueryString);
  548.         return S_OK;
  549.     }
  550.     CATCH_ALL_DUAL
  551. }
  552.  
  553.  
  554. STDMETHODIMP CAutoJPEG::XDualJPEG::ReadSetup(IDispatch* ThisFilter, VARIANT_BOOL FAR* retval)
  555. {
  556.     if (retval == NULL)
  557.         return E_POINTER;
  558.  
  559.     METHOD_PROLOGUE(CAutoJPEG, DualJPEG)
  560.  
  561.     TRY_DUAL(IID_ITurboCADFilter)
  562.     {
  563.         *retval = pThis->ReadSetup(ThisFilter);
  564.         return S_OK;
  565.     }
  566.     CATCH_ALL_DUAL
  567. }
  568.  
  569.  
  570. STDMETHODIMP CAutoJPEG::XDualJPEG::WriteSetup(IDispatch* ThisFilter, VARIANT_BOOL FAR* retval)
  571. {
  572.     if (retval == NULL)
  573.         return E_POINTER;
  574.  
  575.     METHOD_PROLOGUE(CAutoJPEG, DualJPEG)
  576.  
  577.     TRY_DUAL(IID_ITurboCADFilter)
  578.     {
  579.         *retval = pThis->WriteSetup(ThisFilter);
  580.         return S_OK;
  581.     }
  582.     CATCH_ALL_DUAL
  583. }
  584.  
  585. STDMETHODIMP CAutoJPEG::XDualJPEG::Initialize(IDispatch* ThisFilter, VARIANT_BOOL FAR* retval)
  586. {
  587.     if (retval == NULL)
  588.         return E_POINTER;
  589.  
  590.     METHOD_PROLOGUE(CAutoJPEG, DualJPEG)
  591.  
  592.     TRY_DUAL(IID_ITurboCADFilter)
  593.     {
  594.         *retval = pThis->Initialize(ThisFilter);
  595.         return S_OK;
  596.     }
  597.     CATCH_ALL_DUAL
  598. }
  599.  
  600. // Implement ISupportErrorInfo to indicate we support the 
  601. // OLE Automation error handler.
  602. IMPLEMENT_DUAL_ERRORINFO(CAutoJPEG, IID_ITurboCADFilter)
  603.  
  604. // DUAL_SUPPORT_END
  605.  
  606.  
  607.  
  608.